package pattern.singleton;

import com.yue.pattern.singleton.Hungry;
import com.yue.pattern.singleton.LazyTwo;

import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.CountDownLatch;

public class ThreadSafeTestTwo {

    public static void main(String[] args) {

        int count = 200;
//        final Set<Hungry> syncSet = Collections.synchronizedSet(new HashSet<Hungry>());
        CountDownLatch latch = new CountDownLatch(100);
        for (int i = 0; i < count; i++) {
            new Thread(() -> {
//                syncSet.add(Hungry.getInstance());

                    Object object = LazyTwo.getInstance();
                System.out.println(System.currentTimeMillis()+":"+object);

            }).start();

            latch.countDown();
        }

        try {
            latch.await();
            System.out.println("所有线程执行完毕" + latch.getCount());
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

    }
}
